package com.sdust.controller;


import com.sdust.pojos.dto.*;
import com.sdust.result.Result;
import com.sdust.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "文章接口")
public class ArticleController {


    private final ArticleService articleService;

    /**
     * 根据id查询文章
     * @param id
     * @return
     */
    @Operation(summary = "根据id查询文章")
    @GetMapping("/select/{id}")
    public Result getById(@PathVariable Integer id) {
        return articleService.selectById(id);
    }

    /**
     * 新增文章
     * @param dto
     * @return
     */
    @Operation(summary = "新增文章")
    @PostMapping("/add")
    public Result addNewArticle(@RequestBody ArticleDto dto) {
        return articleService.addNewArticle(dto);
    }


    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @Operation(summary = "查询文章列表")
    @PostMapping("/load")
    public Result loadList(@RequestBody ArticleLoadDto dto) {
        return articleService.loadList(dto);
    }

    /**
     * 查询文章评论
     * @return
     */
    @GetMapping("/loadComment/{articleId}")
    public Result loadComment(@PathVariable Integer articleId) {
        return articleService.loadComment(articleId);
    }

    /**
     * 新增评论
     * @param dto
     * @return
     */
    @PostMapping("/addComment")
    public Result addComment(@RequestBody CommentDto dto) {
        return articleService.addComment(dto);
    }

    /**
     * 文章点赞
     * @param dto
     * @return
     */
    @PostMapping("/articleLike")
    public Result articleLike(@RequestBody ArticleUserLikeDto dto) {
        return articleService.articleLike(dto);
    }

    /**
     * 文章取消点赞
     * @param dto
     * @return
     */
    @PostMapping("/articleUndoLike")
    public Result articleUndoLike(@RequestBody ArticleUserLikeDto dto) {
        return articleService.articleUndoLike(dto);
    }

    /**
     * 获取文章点赞数量
     * @param articleId
     * @return
     */
    @GetMapping("/getArticleLikeNum/{articleId}")
    public Result getArticleLikeNum(@PathVariable Integer articleId) {
        return articleService.getArticleLikeNum(articleId);
    }

    /**
     * 文章搜索
     * @param dto
     * @return
     */
    @PostMapping("/searchArticle")
    public Result searchArticle(@RequestBody ArticleSearchDto dto) {
        return articleService.searchArticle(dto);
    }

    /**
     * 文章搜索自动补全
     * @param content
     * @return
     */
    @PostMapping("/completionArticleSearch")
    public Result completionArticleSearch(@RequestParam String content){
        return articleService.completionArticleSearch(content);
    }

    /**
     * 后端项目部署测试接口
     * @return
     */
    @GetMapping("/test")
    public Result deploymentTest() {
        return Result.success("项目部署测试");
    }

}
